export const ZHENGLIUJI_ADMIN_USERINFO = 'zhengliuji-admin-userInfo'
export const ZHENGLIUJI_ACCESS_TOKEN = 'zhengliuji-access-token'
export const ADMIN_PLATFORM_CODE = 'platform-code-admin'
export const ADMIN_PLATFORM_NAME = 'platform-name-admin'
// export const CATCH_PLATFORM_CODE = 'catch-platform-code-admin'
export const CATCH_PLATFORM_CODE = 'platform-code-admin'
export const ADMIN_PLATFORM_USERINFO = 'catch-platform-userInfo-admin'

// 手机号码
// const tel = /^0\d{2,3}-?\d{7,8}$/
// // 座机号码
// const landInPhone = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/

export const checkMoney = (rule, value, callback) => {
  if (
    !/(?:^[1-9]([0-9]+)?(?:\.[0-9]{1,2})?$)|(?:^(?:0){1}$)|(?:^[0-9]\.[0-9](?:[0-9])?$)/.test(value)
  ) {
    callback(new Error('请输入正确的金额'))
  } else {
    callback()
  }
}
export const checkZsNum = (rule, value, callback) => {
  if (!/^[1-9]\d*$/.test(value)) {
    callback(new Error('请输入正整数'))
  } else {
    callback()
  }
}

export const checkNum = (rule, value, callback) => {
  if (!/^[0-9]\d*$/.test(value)) {
    callback(new Error('请输入数字'))
  } else {
    callback()
  }
}

/**
 * 混合电话校验：手机号码、座机
 * @param {*} rule
 * @param {*} value
 * @param {*} callback
 */
export const checkMixPhone = (rule, value, callback) => {
  if (!/^((0\d{2,3}-\d{7,8})|(1[3456789]\d{9}))$/.test(value)) {
    callback(new Error('请输入正确的手机号码'))
  } else {
    callback()
  }
  // if (value && value.length == 11 && !tel.test(value)) {
  //     callback(new Error('请输入正确的手机号码'))
  // } else if (value && value.length == 13 && value.indexOf('-') > 1 && !landInPhone.test(value)) {
  //     callback(new Error('请输入正确的手机号码'))
  // } else {
  //     callback()
  // }
}

export const checkEmail = (rule, value, callback) => {
  if (!/^\w+@[a-z0-9]+\.[a-z]{2,4}$/.test(value)) {
    callback(new Error('请输入正确的邮箱'))
  } else {
    callback()
  }
}

export const checkCertifyNum = (rule, value, callback) => {
  if (
    !/^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/.test(
      value
    )
  ) {
    callback(new Error('请输入正确的身份证号码'))
  } else {
    callback()
  }
}

/**
 * 千位符格式化
 * @param {string|number} text 
 * @returns 
 */
export const digitSymbolFormat = (text) => {
  return text ? ('' + text).replace(/\B(?=(\d{3})+(?!\d))/g, ',') : text
}
